package com.neusoft.demo11;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * 预处理/预编译
 * select * from user where username=? and password=?
 * 之后需要将?替换为具体的值再查询
 */
public class PreparedStatementDemo {
    public static void main(String[] args) {

        try {
            //1. 加载驱动
            Class.forName("com.mysql.jdbc.Driver");
            //2. 获取连接  mysql 3306  oracle 1521
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/basicdemo17","root","123456");
            //3. 获取预编译对象
            PreparedStatement pstmt = conn.prepareStatement("select * from admin where username=? and password=?");
            //4. 将？替换具体的值

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
